/*
 *  xGPS.cpp
 *  xGPS
 *
 *  Created by Miguel Arroz on 10/06/28.
 *  Copyright Miguel Arroz. All rights reserved.
 *
 */

/* Uncomment the following line ONLY if you NEED v2 ONLY APIs. */
/* #define XPLM200 */

#include "xGPS.h"
#include "XPLMPlugin.h"
#include "Announcer.h"

/*============================== REQUIRED METHODS ==============================*/

/*
 * XPluginStart
 */
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
{
	/* Initialize plugin registration and description */
	strcpy(outName, "xGPS");
	strcpy(outSig, "com.xGPS.xGPS_plugin");
	strcpy(outDesc, "Sends information to iPhone xGPS app.");
	
	initDataRefs();
	initBroadcaster();
	startAnnouncer();
	
	return 1;
}


/*
 * XPluginStop
 */
PLUGIN_API void	XPluginStop(void)
{
	stopBroadcaster();
}


/*
 * XPluginEnable
 */
PLUGIN_API int XPluginEnable(void)
{	
	startBroadcasting();
	return 1;
}


/*
 * XPluginDisable
 */
PLUGIN_API void XPluginDisable(void)
{
	stopBroadcasting();
}


/*
 * XPluginReceiveMessage
 */
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFromWho, long inMessage, void *inParam)
{
}

/* ********************* Utilities *********************** */

void xGPSDebug(char *str)
{
    char cat[256] = "xGPSDebug: ";
    strlcat(cat, str, 256-1);
    strcat(cat, "\n");
    XPLMDebugString(cat);
}
